<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>




<div style="padding:0;" class="content tabbed">

	<div id="wiz_create">
		<div class="box no-border">
			<div class="header">
				<h3 class="box-title">事件信息</h3>
				<isperp:help id="help2">
					<p>1、请输入事件信息，包括事件标题和事件描述，事件标题为该事件的关键字；</p>
					<p>2、判断当前事件是否属于合同服务范围：</p>
					<p>
						&nbsp;&nbsp;&nbsp;&nbsp;2.1、事件内容是否在服务范围之内。系统根据事件标题自动匹配项目合同关联的服务目录，单击“显示全部”可以查看所有服务目录，若能匹配，请选择并点击“下一步”，否则拒绝提供服务；</p>
					<p>&nbsp;&nbsp;&nbsp;&nbsp;2.2、关联资产是否在合同范围之内。根据客户提供的资产编号，查找该资产是否在服务合同范围之内，系统默认带出该客户的资产；</p>
					<p>3、如果有匹配的服务目录，请选择，并点击“下一步”；如无法匹配，则告知用户不在服务范围，不予受理。</p>
				</isperp:help>

				<c:if test="${not empty caller }">
					<h2 style="padding:10px;">
						&nbsp;&nbsp;来电号码：<label id="caller" style="color:red	">${caller}</label>
					</h2>
				</c:if>

			</div>

			<form:form commandName="model" cssClass="validate" id="incidentForm"
				action="incident/incident/save">
				<div style="position: relative;height: 100%">
					<div style="position: relative;width:90%;"><jsp:include
							page="step1.jsp"></jsp:include>

					</div>

					<%-- <div class="box"
						style="position: absolute;right:5px;top:10px;width:36%"><jsp:include
							page="step6.jsp"></jsp:include></div> --%>


					<div style="position: relative;clear: both">
						<jsp:include page="step2.jsp"></jsp:include>
						<div id="subway_dealdiv" style="">
							<jsp:include page="step4.jsp"></jsp:include>
							<c:if test="${model.source ne 'Web' }">
								<jsp:include page="step5.jsp"></jsp:include>
							</c:if>
						</div>
					</div>
				</div>
			</form:form>

		</div>
		<script type="text/javascript">
			function formatSelector(rowObject, gridId) {
				return "<a class=\"nui-txt-link\" onclick=\"" + gridId + ".jqGrid.setSelection('" + rowObject.id + "');" + gridId + "Selected();\">选择</a>";
			}

			function formatSrcName(rowObject) {
				return "<a href=\"javascript:isperp.openDialog({contentUrl:'serviceCatalog/service/view?id=" + rowObject.id + "'});\">" + rowObject.name + "</a>";
			}

			function formatCiName(rowObject) {
				return "<a href=\"javascript:isperp.openDialog({contentUrl:'configuration/ci/edit?id=" + rowObject.id + "'});\">" + rowObject.name + "</a>";
			}

			function setServiceCatalogValue(id, name) {

				srcServiceGridSelected(id, name);
				$("#projectServiceDialog").wijdialog("close");
			}

			function setCustomerCiValue(id, name) {
				assAssectGridSelected(id, name);
				$("#customerCiDiglog").wijdialog("close");
			}

			/* var srcServiceGridSelected = function(id, name) {

				if (!id && !name) {
					var selectedRow = srcServiceGrid.getRowData();
					id = selectedRow.id;
					name = selectedRow.name;
				}

				if (id && name) {

					var msg = name + "  <a class='nui-txt-link' href='javascript:void(0)' style='padding-left:5px' onclick='reselectService();'>[修改]</a>";

					$("#selectSrcServiceGrid").hide();
					$("#serviceCategoryId").val(id);
					$("#serviceCategoryMsg").html(msg);
					$("#icdIncidentServiceCatalog").html(name);
				}
			}; */

			var reselectService = function() {
				$("#selectSrcServiceGrid").show();
				$("#serviceCategoryMsg").html("");
				$("#serviceCategoryId").val("");
				$("#icdIncidentServiceCatalog").html("");
			};

			var assAssectGridSelected = function(id, name) {
				if (!id && !name) {
					var selectedRow = assAssectGrid.getRowData();
					id = selectedRow.id;
					name = selectedRow.name;
				}
				if (id && name) {

					var htmlname = "<a href=\"javascript:isperp.openDialog({contentUrl:'configuration/ci/edit?id=" + id + "'});\">" + name + "</a>";

					var msg = htmlname + "  <a class='nui-txt-link' href='javascript:void(0)' style='padding-left:5px' onclick='reselectAsset();'>[修改]</a>";

					$("#selectAssectGridGrid").hide();
					$("#assAssetId").val(id);
					$("#ciIdMsg").html(msg);

					$("#icdIncidentAssets").html(name);
				}
			};

			var reselectAsset = function() {

				$("#selectAssectGridGrid").show();
				$("#ciIdMsg").html("");
				$("#assAssetId").val("");
				$("#icdIncidentAssets").html("");

			};

			function projectServiceCategory_Onclick() {
				isperp.openDialog({
					id : "projectServiceDialog",
					onThisWindow : true,
					title : "选择服务目录",
					windowSize : "normal",
					contentUrl : "serviceCatalog/service/selectEdit?projectId=" + $("#incidentProjectId").val(),
					buttons : [ {
						text : "确定",
						"class" : "nui-mainbtn",
						click : function() {
							var $me = $(this);
							$me.find("iframe")[0].contentWindow.getSelectRow();
						}
					}, {
						text : "关闭",
						"class" : 'grey',
						click : function() {
							$(this).wijdialog("close");
						}
					} ]
				});

			}

			function customerCi_Onclick() {
				isperp.openDialog({
					id : "customerCiDiglog",
					onThisWindow : true,
					title : "选择关联资产",
					windowSize : "normal",
					contentUrl : "customer/customer/customerCiEdit?customerId=" + $("#hidCusUserCustomerId").val(),
					buttons : [ {
						text : "确定",
						"class" : "nui-mainbtn",
						click : function() {
							var $me = $(this);
							$me.find("iframe")[0].contentWindow.getSelectRow();
						}
					}, {
						text : "关闭",
						"class" : 'grey',
						click : function() {
							$(this).wijdialog("close");
						}
					} ]
				});

			}
		</script>

	</div>



</div>


<isperp:buttonList>
	<button onclick="submitIncidentFrom();" class="nui-mainbtn">保存</button>

</isperp:buttonList>
<script type="text/javascript">
	function submitIncidentFrom() {
		//var dealType = '${model.dealType}';
		//changesway(dealType);
		isperp.submitForm({
			formId : "incidentForm"

		});

	}
	function updateRelateCi() {
		var ciId = $("#ciId").val();
		var icdId = '${model.id}';
		if (ciId != "") {
			$.ajax({
				url : "incident/incident/updateRelateCi?relationId=" + icdId + "&ciId=" + ciId,
				success : function(data) {
					//return true;
				}
			});
			return true;
		} else {
			return true;
		}
	}
	//事件标题变化时，自动匹配服务目录
	$("#incidentTitle,#incidentProjectId").change(function() {

		var title = $("#incidentTitle").val();
		var projectId = $("#incidentProjectId").val();

		if (title) {

			srcServiceGrid.jqGrid.setGridParam({
				url : "serviceCatalog/service/searchByKeyword?keyword=" + $("#incidentTitle").val() + "&projectId=" + projectId
			});
			srcServiceGrid.search();
			searchLimiarIncident();
		}
	});

	//搜索类似事件
	var searchLimiarIncident = function() {

		var title = $("#incidentTitle").val();
		//查询类似事件
		if (title) {
			var condition = {
				"field" : "title",
				"op" : "cn",
				"data" : title
			};
			similarIncidentGrid.search(condition);
		}
	};

	var serviceSelected = function() {

		var selectedRow = srcServiceGrid.getRowData();
		if (selectedRow && selectedRow.name) {

			var msg = selectedRow.name + "  <a href='javascript:void(0)' style='color:blue;padding-left:5px' onclick='reselectService();'>[修改]</a>";

			$("#selectSrcServiceGrid").hide();
			$("#serviceCategoryId").val(selectedRow.id);
			$("#serviceCategoryMsg").html(msg);
			$("#icdIncidentServiceCatalog").html(selectedRow.name);
		}
	};

	var reselectService = function() {

		$("#selectSrcServiceGrid").show();
		$("#serviceCategoryMsg").html("");
		$("#serviceCategoryId").val("");
		$("#icdIncidentServiceCatalog").html("");
	};

	var assetSelected = function() {

		var selectedRow = assAssectGrid.getRowData();
		if (selectedRow && selectedRow.name) {

			var htmlname = "<a href=\"javascript:isperp.openDialog({contentUrl:'configuration/ci/edit?id=" + selectedRow.id + "'});\">" + selectedRow.name + "</a>";

			var msg = htmlname + "  <a href='javascript:void(0)' style='color:blue;padding-left:5px' onclick='reselectAsset();'>[修改]</a>";

			$("#selectAssectGridGrid").hide();
			$("#assAssetId").val(selectedRow.id);
			$("#ciIdMsg").html(msg);

			$("#icdIncidentAssets").html(selectedRow.name);
		}
	};

	var reselectAsset = function() {

		$("#selectAssectGridGrid").show();
		$("#ciIdMsg").html("");
		$("#assAssetId").val("");
		$("#icdIncidentAssets").html("");

	};

	//改变处理方式
	function changesway(v) {
		/* if (v == "1") {
			$("#subway_dealdiv").show();
			$("#subway_dealdiv").find("input").attr("disabled", false);
			$("#subway_dealdiv").find("select").attr("disabled", false);
			$("#subway_dealdiv").find("textarea").attr("disabled", false);
			$("#supporter_tr1").hide();
			$("#supporter_tr1").find("input").attr("disabled", 'disabled');
			$("#supporter_tr2").hide();
			$("#supporter_tr2").find("input").attr("disabled", 'disabled');
			$("#projectMemberGrid_div").hide();

			$("#reject_tr").hide();
			$("#reject_tr").find("textarea").attr('disabled', 'disabled');
		} else if (v == "2") {
			$("#subway_dealdiv").hide();
			$("#subway_dealdiv").find("input").attr('disabled', 'disabled');
			$("#subway_dealdiv").find("select").attr('disabled', 'disabled');
			$("#subway_dealdiv").find("textarea").attr('disabled', 'disabled');
			$("#projectMemberGrid_div").show();
			$("#supporter_tr1").show();
			$("#supporter_tr1").find("input").attr("disabled", false);
			$("#supporter_tr2").show();
			$("#supporter_tr2").find("input").attr("disabled", false);

			$("#reject_tr").hide();
			$("#reject_tr").find("textarea").attr('disabled', 'disabled');
		} else {
			$("#subway_dealdiv").hide();
			$("#subway_dealdiv").find("input").attr("disabled", false);
			$("#subway_dealdiv").find("select").attr("disabled", false);
			$("#subway_dealdiv").find("textarea").attr("disabled", false);

			$("#projectMemberGrid_div").hide();
			$("#supporter_tr1").hide();
			$("#supporter_tr1").find("input").attr("disabled", false);
			$("#supporter_tr2").hide();
			$("#supporter_tr2").find("input").attr("disabled", false);
			$("#reject_tr").show();
			$("#reject_tr").find("textarea").attr('disabled', false);

		} */
	}

	$(document).ready(function() {
		var dealType = '${model.dealType}';
		//changesway(dealType);
	})
</script>
<c:if test="${not empty model.cusUserId}">
	<script type="text/javascript">
		setCusUser("${model.cusUserId}");
	</script>
</c:if>
<c:if test="${modelEdit eq true }">


	<script type="text/javascript">
		if ("${model.serviceCategoryId}" && "${model.serviceCategoryId}" != "") {
			srcServiceGridSelected("${model.serviceCategoryId}", "${serviceCategoryName}");
		}
		searchLimiarIncident();
	</script>

	<c:choose>
		<c:when test="${empty model.ciId }">
			<script type="text/javascript">
				assAssectGrid.jqGrid.setGridParam({
					url : "configuration/ci/listByCusUserId?cusUserId=" + userId
				});
			</script>
		</c:when>
		<c:otherwise>
			<script type="text/javascript">
				assAssectGridSelected("${model.ciId}", "${ciName}");
			</script>
		</c:otherwise>
	</c:choose>


</c:if>



